package ru.vsu.cs.brainsaver.game;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class SpriteAnimation {
	private Bitmap mAnimation;
	private Rectangle mRect;
	private int mXPos;
	private int mYPos;
	private int mFPS;
    private int mNoOfFrames;
    private int mCurrentFrame;
    private long mFrameTimer;
    private int mSpriteHeight;
    private int mSpriteWidth;
	
    public void Init(Bitmap theBitmap, int Height, int Width, int theFPS, int theFrameCount) {
        mAnimation = theBitmap;
        mSpriteHeight = Height;
        mSpriteWidth = Width;
        mRect.y = 0;
        mRect.height = mSpriteHeight;
        mRect.x = 0;
        mRect.width = mSpriteWidth;
        mFPS = 1000 /theFPS;
        mNoOfFrames = theFrameCount;
    }
    
    public void Update(long GameTime) {
        if(GameTime > mFrameTimer + mFPS ) {
            mFrameTimer = GameTime;
            mCurrentFrame +=1;
     
            if(mCurrentFrame >= mNoOfFrames) {
                mCurrentFrame = 0;
            }
        }
     
        mRect.x = mCurrentFrame * mSpriteWidth;
        mRect.width = mRect.x + mSpriteWidth;
    }
    
    public void draw(Canvas canvas,int getXPos,int getYPos) {
        Rectangle dest = new Rectangle(getXPos, getYPos, getXPos + mSpriteWidth,
                        getYPos + mSpriteHeight);
     
        //canvas.drawBitmap(mAnimation, Rectangle, dest, null);
    }

}
